package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TableData;
import com.ruoyi.system.service.ITableDataService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 业务数据信息Controller
 * 
 * @author chenming
 * @date 2024-10-16
 */
@RestController
@RequestMapping("/system/tableData")
public class TableDataController extends BaseController
{
    @Autowired
    private ITableDataService tableDataService;

    /**
     * 查询业务数据信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:tableData:list')")
    @GetMapping("/list")
    public TableDataInfo list(TableData tableData)
    {
        startPage();
        List<TableData> list = tableDataService.selectTableDataList(tableData);
        return getDataTable(list);
    }

    /**
     * 导出业务数据信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:tableData:export')")
    @Log(title = "业务数据信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TableData tableData)
    {
        List<TableData> list = tableDataService.selectTableDataList(tableData);
        ExcelUtil<TableData> util = new ExcelUtil<TableData>(TableData.class);
        util.exportExcel(response, list, "业务数据信息数据");
    }

    /**
     * 获取业务数据信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:tableData:query')")
    @GetMapping(value = "/{tableId}")
    public AjaxResult getInfo(@PathVariable("tableId") Long tableId)
    {
        return success(tableDataService.selectTableDataByTableId(tableId));
    }

    /**
     * 新增业务数据信息
     */
    @PreAuthorize("@ss.hasPermi('system:tableData:add')")
    @Log(title = "业务数据信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TableData tableData)
    {
        return toAjax(tableDataService.insertTableData(tableData));
    }

    /**
     * 修改业务数据信息
     */
    @PreAuthorize("@ss.hasPermi('system:tableData:edit')")
    @Log(title = "业务数据信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TableData tableData)
    {
        return toAjax(tableDataService.updateTableData(tableData));
    }

    /**
     * 删除业务数据信息
     */
    @PreAuthorize("@ss.hasPermi('system:tableData:remove')")
    @Log(title = "业务数据信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tableIds}")
    public AjaxResult remove(@PathVariable Long[] tableIds)
    {
        return toAjax(tableDataService.deleteTableDataByTableIds(tableIds));
    }
}
